import subprocess

# cmd = "cmd.exe /c dir"    显示C盘 文件信息
cmd = "cmd.exe /c dir"
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
curline = p.stdout.readline()
while (curline != b''):
    curline = p.stdout.readline()
    # 此处注意返回信息编码问题
    # print(str(curline, 'utf-8'))
    print(curline.decode("gbk", "ignore"))
p.wait()
# 执行成功p.returncode 为0
print("p.returncode:" + str(p.returncode))
